package com.stm.web.controller.basicData;

import java.util.List;

import com.stm.basicData.domain.KfToolsType;
import com.stm.basicData.service.KfToolsTypeService;
import com.stm.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.stm.common.annotation.Log;
import com.stm.common.enums.BusinessType;
import com.stm.basicData.domain.ToolsAlarm;
import com.stm.basicData.service.IToolsAlarmService;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.utils.poi.ExcelUtil;

/**
 * 预警关联 信息操作处理
 * 
 * @author wyc
 * @date 2019-04-08
 */
@Controller
@RequestMapping("/basicData/toolsAlarm")
public class ToolsAlarmController extends BaseController
{
    private String prefix = "basicData/toolsAlarm";
	
	@Autowired
	private IToolsAlarmService toolsAlarmService;

	@Autowired
    private KfToolsTypeService kfToolsTypeService;

	
	@RequiresPermissions("basicData:toolsAlarm:view")
	@GetMapping()
	public String toolsAlarm(ModelMap mmap)
    {
    	mmap.put("user", ShiroUtils.getSysUser());
	    return prefix + "/toolsAlarm";
	}
	
	/**
	 * 查询预警关联列表
	 */
	@RequiresPermissions("basicData:toolsAlarm:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ToolsAlarm toolsAlarm)
	{
		startPage();
        List<ToolsAlarm> list = toolsAlarmService.selectToolsAlarmList(toolsAlarm);
		return getDataTable(list);
	}

    /**
     * 初始化下拉列表数据
     * 查询出所有工具类型
     */
    @PostMapping("/initToolsType")
    @ResponseBody
    public List<KfToolsType> initToolsType(KfToolsType toolsType)
    {
        return  kfToolsTypeService.selectAllPageList(toolsType);
    }

	/**
	 * 导出预警关联列表
	 */
	@RequiresPermissions("basicData:toolsAlarm:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ToolsAlarm toolsAlarm)
    {
    	List<ToolsAlarm> list = toolsAlarmService.selectToolsAlarmList(toolsAlarm);
        ExcelUtil<ToolsAlarm> util = new ExcelUtil<ToolsAlarm>(ToolsAlarm.class);
        return util.exportExcel(list, "toolsAlarm");
    }
	
	/**
	 * 新增预警关联
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存预警关联
	 */
	@RequiresPermissions("basicData:toolsAlarm:add")
	@Log(title = "预警关联", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ToolsAlarm toolsAlarm)
	{
		toolsAlarm.setCreateBy(ShiroUtils.getLoginName());
		toolsAlarm.setDprtcode(ShiroUtils.getSysUser().getDeptId());
		return toAjax(toolsAlarmService.insertToolsAlarm(toolsAlarm));
	}

	/**
	 * 修改预警关联
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		ToolsAlarm toolsAlarm = toolsAlarmService.selectToolsAlarmById(id);
		mmap.put("toolsAlarm", toolsAlarm);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存预警关联
	 */
	@RequiresPermissions("basicData:toolsAlarm:edit")
	@Log(title = "预警关联", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ToolsAlarm toolsAlarm)
	{
		toolsAlarm.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(toolsAlarmService.updateToolsAlarm(toolsAlarm));
	}
	
	/**
	 * 删除预警关联
	 */
	@RequiresPermissions("basicData:toolsAlarm:remove")
	@Log(title = "预警关联", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(toolsAlarmService.deleteToolsAlarmByIds(ids));
	}
	
}
